Screen Reader Only (SrOnly)
Wrap this invisible component around text that needs to be hidden visually, but kept available to assistive technologies, such as screen readers.
#Examples
We sometimes leave out text in our UI, because it creates visual clutter and its message is communicated through context. That explains why some of our table column headers are empty. Despite the empty headers, the content and purpose of the columns remains clear to sighted uses.
This is not the case for non-sighted users and that’s where the SrOnly component comes in. This component enables us to hide text, but keep it available to assistive technologies, such as screen readers. So, empty table column headers actually do have labels, they’re just hidden from view.
#Default
The example below may seem empty. However, the Code section shows that it actually contains an SrOnly
component wrapped around a sentence. If you toggle on the HTML output, you'll see that this component outputs a div
.
<SrOnly>This text is invisible, but available to assistive technologies.</SrOnly>
#Status
When the status of an element in the UI changes, this is sometimes only communicated visually. The status
property enables us to keep assistive technology users informed of such changes. When set to true
, role=“status”
and aria-atomic=“true”
are added to the div
that the SrOnly
component outputs. As a result, whenever the content of that div
changes, its new content is announced to assistive technologies, such as a screen reader.
<SrOnly status>{isLoading && "Loading"}</SrOnly>
#Focus
This component can also be used to assist sighted users who navigate using the keyboard. SrOnly components are visible when given focus. This functionality can be useful, for instance, to create links that make it possible to skip content so that it is not captured by assistive technology devices, such as screen readers.
<SrOnly>
<Link href="#properties">Skip to properties section</Link>
</SrOnly>
#Properties
Property | Description | Defined | Value |
---|---|---|---|
childrenOptional | element Content of the element | ||
statusOptional | boolean Notifies assistive technologies of changes to the content. WARNING: SrOnly component must be present before content change for this to work. | ||
styleOptional | object Style object to apply custom inline styles (only intended for special cases) | ||
isInlineOptional | boolean Will replace the SrOnly div with a span | ||
idOptional | string Optional ID | ||
boolean Indicates whether the element is exposed to an accessibility API. |
#Guidelines
#Best practices
#Do not use when
#Accessibility
Explore detailed guidelines for this component: Accessibility Specifications